﻿#pragma once

#include "Block.h"

// 游戏
class Game {
    // 状态
    public: enum Status {
        END,    // 已结束
        PAUSED, // 暂停中
        PLAYING // 游戏中
    };

    private: CWnd* mCallback;       // 回调
    private: Block* mCurBlock;      // 当前方块
    private: int mDifficulty;       // 难度
    private: BOOL mEnableMusic;     // 音乐开关
    private: CWnd* mGameBoard;      // 游戏区域
    private: CDC* mGameBoardDrawer; // 游戏区域绘图者
    private: Block* mNextBlock;     // 下一个方块
    private: CWnd* mPreview;        // 预览区域
    private: CDC* mPreviewDrawer;   // 预览区域绘图者
    private: int mScore;            // 得分
    private: Status mStatus;        // 状态
    private: int mTop;              // 有方块的最高行
    public: static ColorGrid sExistentBlocks[Const::GAME_BOARD_GRID_COUNT_V][Const::GAME_BOARD_GRID_COUNT_H];   // 累积的方块

    public: Game(CWnd*, CWnd*, CDC*, CWnd*, CDC*);
    public: ~Game();
    private: void CheckRow();
    private: Block* CreateRandBlock();
    private: void DrawExistentBlock();
    private: void DrawGameBoard();
    private: void DrawPreview();
    private: void GameOver(BOOL);
    public: Status GetStatus();
    private: BOOL IsLost();
    private: BOOL IsWon();
    private: void MoveBlockDown();
    private: void NextBlock();
    public: BOOL OnKeyPressed(UINT);
    public: void OnTimer();
    public: void Pause();
    public: BOOL PlayMusic();
    private: void ReleaseRow(int);
    public: void Start();
};
